package com.lanou3g.dllo.baidumusic.search;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.tools.SingleVolley;

import java.util.List;

/**
 * Created by dllo on 16/7/2.
 */
public class SearchAdapter extends BaseAdapter{
    private SearchBean searchBean;
    private List<SearchBean.ResultBean.SongInfoBean.SongListBean> list;
    private Context context;

    public SearchAdapter(Context context) {
        this.context = context;
    }

    public void setSearchBean(SearchBean searchBean) {
        this.searchBean = searchBean;
        list = searchBean.getResult().getSong_info().getSong_list();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder =null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_search,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.search_singername.setText(list.get(position).getAuthor());
        holder.searchSongsName.setText(list.get(position).getTitle());
        return convertView;
    }
    class ViewHolder {
        ImageView searchSingerPhoto;
        TextView searchSongsName,search_singername;
        public ViewHolder(View view) {
            searchSingerPhoto = (ImageView) view.findViewById(R.id.search_singerphoto);
            searchSongsName = (TextView) view.findViewById(R.id.search_songsname);
            search_singername = (TextView) view.findViewById(R.id.search_singername);
        }

    }
}
